<?php

class Site_Model extends Model{
    function __construct(){
        parent::Model();
    }
    function getAll($table){
        $query = $this->db->get($table);
        return $query;
    }
    
	// get number of data in database
	function count_all($table){
		return $this->db->count_all($table);
	}
	// get data by id
	function get_by_id($table, $id){
		$this->db->where('id', $id);
		return $this->db->get($table);
	}
    // get data by a specific field
	function get_by_field($table, $field, $data){
		$this->db->where($field, $data);
		return $this->db->get($table);
	}
	// add new data
	function save($table, $data){
		$this->db->insert($table, $data);
		return $this->db->insert_id();
	}
	// update data by id
	function update($table, $id, $data){
		$this->db->where('id', $id);
		$this->db->update($table, $data);
	}
	// delete data by id
	function delete($table, $id){
		$this->db->where('id', $id);
		$this->db->delete($table);
	}

}